package com.bdqn.BookManage.servlet;

import com.bdqn.BookManage.biz.BookInfoBiz;
import com.bdqn.BookManage.biz.impl.BookInfoBizImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 删除图书信息处理器
 * @date : 2020-07-21 13:38
 **/
@WebServlet("/deleteBookInfo")
public class DeleteBookInfoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    /**
     * 删除指定的图书信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /* 设置编码集 */
        resp.setCharacterEncoding("GBK");
        req.setCharacterEncoding("utf-8");

        PrintWriter out = resp.getWriter();
        BookInfoBiz bookInfoBiz = new BookInfoBizImpl();

        /* 取值 */
        Integer bookId = Integer.valueOf(req.getParameter("bookId"));

        boolean yes = bookInfoBiz.removeBookInfo(bookId);

        /* 处理结果 */
        String conclusion = yes?"删除成功!":"网络繁忙~";
        out.print("<script>alert('"+conclusion+"');location.href = '/BookManage/queryBook';</script>");
        out.flush();
        out.close();
    }
}
